<?php
require_once(dirname(__FILE__) . '/../../includes/spip_launcher.php');
include_spip('functions/pdk_common');
require_once(_DIR_PLUGIN_PDK.'classes/simpletest/class.PdkTest.php');

class TestBaliseEcatalogueProductPrice extends PdkTest {
	/**
     *  ProductModel
     */
    protected $product_mdl;

	/**
     *  CurrencyModel
     */
    protected $currency_mdl;
	
    /**
     *  RubriqueCurrencyModel
     */
    private $rub_cur_mdl;
    
    /**
     *  PdkRubriqueModel
     */
    private $rub_mdl;
	
	/**
     *  PdkArticleModel
     */
    private $article_mdl;
	
    public function __construct() {
        parent::__construct();
		
		$pdk_models = array();
		$this->product_mdl = pdk_load_class('ProductModel','classes');
        $pdk_models['ProductModel'] = $this->product_mdl;
        $this->rub_cur_mdl = pdk_load_class('RubriqueCurrencyModel','classes');
        $pdk_models['RubriqueCurrencyModel'] = $this->rub_cur_mdl;
        $this->rub_mdl = pdk_load_class('PdkRubriqueModel','classes/models');
        $pdk_models['PdkRubriqueModel'] = $this->rub_mdl;                
        $this->currency_mdl = pdk_load_class('CurrencyModel','classes');
        $pdk_models['CurrencyModel'] = $this->currency_mdl;       
		$this->article_mdl = pdk_load_class('PdkArticleModel','classes');
		$pdk_models['PdkArticleModel'] = $this->article_mdl;
		$this->AddPdkModels($pdk_models);
		
		
		
		$this->dropTestTables = ECATALOGUE_TESTS_DROP_TEST_TABLES;
    }
    
    /**
     *  Run before each test
     */
    function setUp() {
        parent::setUp();    
    }
    
    /**
     *  Run after each test
     */
    function tearDown() {
        parent::tearDown();
    }
    
    function __destruct() {
        // Call parent destructor to delete created tables
        parent::__destruct();
    }
	
	function TestTagMustExist(){
		$code = '[(#ECATALOGUE_PRODUCT_PRICE{1}|oui)ok]';
        $this->assertOkCode($code);
	}
	
	function TestPriceInMainCurrency() {
		$code = '#ECATALOGUE_PRODUCT_PRICE{1, UAH}';        
		$this->assertEqual(90, $this->recuperer_code($code));
		
		$code = '#ECATALOGUE_PRODUCT_PRICE{2}';
		$this->assertEqual(80, $this->recuperer_code($code));
		
		$code = '#ECATALOGUE_PRODUCT_PRICE{3, UAH, price}';
		$this->assertEqual(70, $this->recuperer_code($code));
	}
	
	function TestPriceConverted() {
		$code = '#ECATALOGUE_PRODUCT_PRICE{1, USD}';
		$this->assertEqual(11.25, $this->recuperer_code($code));
	}
	
	function TestOldPrice() {
		$code = '#ECATALOGUE_PRODUCT_PRICE{1, UAH, priceold}';        
		$this->assertEqual(200, $this->recuperer_code($code));
	}
}
